//
//  CKLoadingView.m
//  CKApp
//
//  Created by CC on 2020/8/29.
//  Copyright © 2020 This Moment. All rights reserved.
//

#import "CKLoadingView.h"

@interface CKLoadingView ()
@property(nonatomic, weak) IBOutlet UIImageView* loadingImageView;
@end

@implementation CKLoadingView

+ (CKLoadingView*)loadFromBundle {
  CKLoadingView* loadingView = [[NSBundle mainBundle] loadNibNamed:@"CKLoadingView" owner:nil options:nil].firstObject;
  loadingView.frame = CGRectMake(0, 0, 80, 80);
  loadingView.backgroundColor = [UIColor clearColor];
  return loadingView;
}

- (void)startAnimating {
  CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  animation.toValue = [NSNumber numberWithFloat:M_PI * 2];
  animation.duration = 0.8;
  [animation setCumulative:YES];
  animation.repeatCount = MAXFLOAT;
  [self.loadingImageView.layer addAnimation:animation forKey:@"rotationAnimation"];
}

- (void)stopAnimating {
  [self.loadingImageView.layer removeAnimationForKey:@"rotationAnimation"];

}

@end
